﻿using Gargoyle.Roton;
using System;
using System.Collections.Generic;
using System.Text;

namespace Gargoyle.ZZT
{
    public class Tile
    {
        private Pointer pointer;

        public Tile()
        {
            pointer = new Pointer(new byte[2]);
        }

        public Tile(Memory memory)
        {
            pointer = memory.GetRelativePointer(0);
        }

        public Tile(Memory memory, int offset)
        {
            pointer = memory.GetRelativePointer(offset);
        }

        public Tile(Pointer pointer)
        {
            this.pointer = pointer;
        }

        public Tile(byte newElement, byte newColor)
        {
            pointer = new Pointer(new byte[2]);
            Element = newElement;
            Color = newColor;
        }

        public static bool operator ==(Tile t1, Tile t2)
        {
            return ((t1.Element == t2.Element) && (t1.Color == t2.Color));
        }

        public static bool operator !=(Tile t1, Tile t2)
        {
            return ((t1.Element != t2.Element) || (t1.Color != t2.Color));
        }

        public void CopyFrom(Tile source)
        {
            Element = source.Element;
            Color = source.Color;
        }

        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public override string ToString()
        {
            return "Tile (Element=" + Element.ToString() + ", Color=" + Color.ToString() + ")";
        }

        public byte Color
        {
            get { return pointer[1]; }
            set { pointer[1] = value; }
        }

        public byte Element
        {
            get { return pointer[0]; }
            set { pointer[0] = value; }
        }
    }
}
